package com.demostic.demostic_test.utils;

import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Region;
import android.view.MotionEvent;

import com.demostic.demostic_test.entity.ForbiddenInfo;
import com.demostic.demostic_test.entity.LineInfo;
import com.demostic.demostic_test.entity.VirTualInfo;
import com.demostic.demostic_test.ui.MapEditView901;

import org.java_websocket.drafts.Draft_75;

import java.util.ArrayList;

public class DataUtils {
    private static final String TAG = DataUtils.class.getSimpleName();
    public static Point disPoint = new Point();
    public static Path jgPath = new Path();
    public static Region jgRegion = new Region();
    private static float tempx;
    private static float tempy;

    public static ArrayList<Integer> intToHex(byte[] byte_receive) {
        ArrayList<Integer> hexList = new ArrayList<>();
        for (int i = 4; i < byte_receive.length; i++) {
            hexList.add(Integer.valueOf(byte_receive[i] & Draft_75.END_OF_FRAME));
        }
        return hexList;
    }

    public static int bytesToInt2(byte[] src, int offset) {
        return ((src[offset] & Draft_75.END_OF_FRAME) << 8) | (src[offset + 1] & Draft_75.END_OF_FRAME);
    }

    public static int bytesToInt(byte[] src, int offset) {
        int value = ((src[offset] & 0xFF) << 8) | (src[offset + 1] & 0xFF);
        if ((src[offset] & 128) == 128) {
            return value - 65536;
        }
        return value;
    }

    public static int bytesToUInt(byte[] src, int offset) {
        return ((src[offset] & 0xFF) << 8) | (src[offset + 1] & 0xFF);
    }

    public static byte[] intToBytes(int value) {
        return new byte[]{(byte) ((value >> 8) & 255), (byte) (value & 255)};
    }

    public static byte[] concat(byte[] a, byte[] b, int offset) {
        byte[] c = new byte[((a.length + b.length) - offset)];
        System.arraycopy(a, 0, c, 0, a.length);
        System.arraycopy(b, offset, c, a.length, b.length - offset);
        return c;
    }

    public static byte[] concats(byte[] a) {
        byte[] c = new byte[(a.length - 3)];
        System.arraycopy(a, 3, c, 0, a.length - 3);
        return c;
    }

    public static byte[] concats_(byte[] a) {
        byte[] c = new byte[(a.length - 4)];
        System.arraycopy(a, 4, c, 0, a.length - 4);
        return c;
    }

    public static PointF midPoint(MotionEvent event) {
        return new PointF((event.getX(0) + event.getX(1)) / 2.0f, (event.getY(0) + event.getY(1)) / 2.0f);
    }

    public static float distance(MotionEvent event) {
        float x = 0.0f;
        float y = 0.0f;
        try {
            x = event.getX(0) - event.getX(1);
            y = event.getY(0) - event.getY(1);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
        return (float) Math.sqrt((double) ((x * x) + (y * y)));
    }

    public static float distance2Point(float x1, float y1, float x2, float y2) {
        float disX = x1 - x2;
        float disY = y1 - y2;
        return (float) Math.sqrt((double) ((disX * disX) + (disY * disY)));
    }

    public static float getDegree(PointF centerP, PointF preMoveP, PointF curMoveP) {
        double a = (double) distance2PointF(centerP, preMoveP);
        double b = (double) distance2PointF(preMoveP, curMoveP);
        double c = (double) distance2PointF(centerP, curMoveP);
        double cosb = (((a * a) + (c * c)) - (b * b)) / ((2.0d * a) * c);
        if (cosb >= 1.0d) {
            cosb = 1.0d;
        }
        float degree = (float) Math.toDegrees(Math.acos(cosb));
        PointF centerTopreMoveP = new PointF(preMoveP.x - centerP.x, preMoveP.y - centerP.y);
        PointF centerTocurMoveP = new PointF(curMoveP.x - centerP.x, curMoveP.y - centerP.y);
        if ((centerTopreMoveP.x * centerTocurMoveP.y) - (centerTopreMoveP.y * centerTocurMoveP.x) < 0.0f) {
            return -degree;
        }
        return degree;
    }

    public static Point obtainRoationPoint(Point center, Point source, float degree) {
        disPoint.x = source.x - center.x;
        disPoint.y = source.y - center.y;
        double orgRadian = 0.0d;
        Point resultPoint = new Point();
        double distance = Math.sqrt((double) ((disPoint.x * disPoint.x) + (disPoint.y * disPoint.y)));
        if (disPoint.x == 0 && disPoint.y == 0) {
            return center;
        }
        if (disPoint.x >= 0 && disPoint.y >= 0) {
            orgRadian = Math.asin(((double) disPoint.y) / distance);
        } else if (disPoint.x < 0 && disPoint.y >= 0) {
            orgRadian = Math.asin(((double) Math.abs(disPoint.x)) / distance) + 1.5707963267948966d;
        } else if (disPoint.x < 0 && disPoint.y < 0) {
            orgRadian = Math.asin(((double) Math.abs(disPoint.y)) / distance) + 3.141592653589793d;
        } else if (disPoint.x >= 0 && disPoint.y < 0) {
            orgRadian = Math.asin(((double) disPoint.x) / distance) + 4.71238898038469d;
        }
        double aftRadian = Math.toRadians(Math.toDegrees(orgRadian) + ((double) degree));
        resultPoint.x = (int) Math.round(Math.cos(aftRadian) * distance);
        resultPoint.y = (int) Math.round(Math.sin(aftRadian) * distance);
        resultPoint.x += center.x;
        resultPoint.y += center.y;
        return resultPoint;
    }

    public static float distance2PointF(PointF pf1, PointF pf2) {
        float disX = pf2.x - pf1.x;
        float disY = pf2.y - pf1.y;
        return (float) Math.sqrt((double) ((disX * disX) + (disY * disY)));
    }

    public static double judgedVirtual(int sx, int sy, int ex, int ey, Point point) {
        double virK = (((double) (ey - sy)) * 1.0d) / ((double) (ex - sx));
        double virInc = ((double) ey) - (((double) ex) * virK);
        double a = 1.0d + (virK * virK);
        double b = 2.0d * (((virK * virInc) - ((double) point.x)) - (((double) point.y) * virK));
        return (b * b) - ((4.0d * a) * (((((double) ((point.x * point.x) + (point.y * point.y))) + (virInc * virInc)) - (((double) (point.y * 2)) * virInc)) - 100.0d));
    }

    public static double judgedVirtual_(int sx, int sy, int ex, int ey, com.demostic.demostic_test.entity.Point point) {
        double k = (((double) (ey - sy)) * 1.0d) / ((double) (ex - sx));
        double bn = ((double) ey) - (((double) ex) * k);
        double a = 1.0d + (k * k);
        double b = 2.0d * (((k * bn) - ((double) point.x)) - (((double) point.y) * k));
        return (b * b) - ((4.0d * a) * (((((double) ((point.x * point.x) + (point.y * point.y))) + (bn * bn)) - (((double) (point.y * 2)) * bn)) - 100.0d));
    }

    public static int judgedVirAndCharge(int sx, int sy, int ex, int ey, com.demostic.demostic_test.entity.Point point) {
        double judDis;
        double k = (((double) (ey - sy)) * 1.0d) / ((double) (ex - sx));
        double d = ((double) ey) - (((double) ex) * k);
        double chuiX = ((((k * k) * ((double) sx)) + (((double) (point.y - sy)) * k)) + ((double) point.x)) / ((k * k) + 1.0d);
        double chuiY = ((chuiX - ((double) sx)) * k) + ((double) sy);
        int cx = (int) chuiX;
        int cy = (int) chuiY;
        MyLog.e(TAG, "test chuizu judge int:" + point.x + "," + point.y + "<->" + cx + "," + cy + "<->" + sx + "," + sy + "<->" + ex + "," + ey);
        if ((Math.min(sx, ex) >= cx || cx >= Math.max(sx, ex)) && (Math.min(sy, ey) >= cy || cy >= Math.max(sy, ey))) {
            double p1dis = Math.sqrt((double) (((point.x - sx) * (point.x - sx)) + ((point.y - sy) * (point.y - sy))));
            double p2dis = Math.sqrt((double) (((point.x - ex) * (point.x - ex)) + ((point.y - ey) * (point.y - ey))));
            if (p1dis > p2dis) {
                judDis = p2dis;
            } else {
                judDis = p1dis;
            }
            MyLog.e(TAG, "test chuizu not on the vir:" + judDis);
        } else {
            judDis = Math.sqrt(((((double) point.x) - chuiX) * (((double) point.x) - chuiX)) + ((((double) point.y) - chuiY) * (((double) point.y) - chuiY)));
            MyLog.e(TAG, "test chuizu on the vir:" + judDis);
        }
        return (int) judDis;
    }

    public static PointF getRadiusPoint(int sx, int sy, int ex, int ey) {
        float mx;
        float my;
        double k = (((double) (ey - sy)) * 1.0d) / ((double) (ex - sx));
        double bn = ((double) ey) - (((double) ex) * k);
        double a = 1.0d + (k * k);
        double b = 2.0d * (((k * bn) - ((double) sx)) - (((double) sy) * k));
        double c = ((((double) ((sx * sx) + (sy * sy))) + (bn * bn)) - (((double) (sy * 2)) * bn)) - 400.0d;
        double x1 = ((-b) + Math.sqrt((b * b) - ((4.0d * a) * c))) / (2.0d * a);
        double x2 = ((-b) - Math.sqrt((b * b) - ((4.0d * a) * c))) / (2.0d * a);
        if (ex > sx) {
            if (x1 <= x2) {
                x1 = x2;
            }
            mx = (float) x1;
        } else if (ex < sx) {
            if (x1 >= x2) {
                x1 = x2;
            }
            mx = (float) x1;
        } else {
            mx = (float) ex;
        }
        if (ex != sx) {
            my = (float) ((((double) mx) * k) + bn);
        } else if (ey > sy) {
            my = (float) (sy + 20);
        } else if (ey >= sy) {
            return new PointF(tempx, tempy);
        } else {
            my = (float) (sy - 20);
        }
        tempx = mx;
        tempy = my;
        return new PointF(mx, my);
    }

    public static boolean getPointToLineDistence(int sx, int sy, int ex, int ey, int jugx, int jugy) {
        if (Math.abs(sx - ex) >= 0 && Math.abs(sx - ex) <= 3 && Math.min(sy, ey) < jugy && jugy < Math.max(sy, ey)) {
            double judDis = (double) Math.abs(sx - jugx);
            MyLog.e(TAG, "getPointToLineDistence 斜率不存在:" + judDis);
            if (0.0d > judDis || judDis > 10.0d) {
                return false;
            }
            return true;
        } else if (Math.abs(sy - ey) >= 0 && Math.abs(sy - ey) <= 3 && Math.min(sx, ex) < jugx && jugx < Math.max(sx, ex)) {
            double judDis2 = (double) Math.abs(sy - jugy);
            MyLog.e(TAG, "getPointToLineDistence 斜率为0:" + judDis2);
            return 0.0d <= judDis2 && judDis2 <= 10.0d;
        } else if (Math.min(sx, ex) >= jugx || jugx >= Math.max(sx, ex) || Math.min(sy, ey) >= jugy || jugy >= Math.max(sy, ey)) {
            MyLog.e(TAG, "getPointToLineDistence 数据:" + sx + "," + sy + "," + ex + "," + ey + "," + jugx + "," + jugy + ",0.0");
            return false;
        } else {
            double k = (((double) (ey - sy)) * 1.0d) / ((double) (ex - sx));
            double chuiX = ((((k * k) * ((double) sx)) + (((double) (jugy - sy)) * k)) + ((double) jugx)) / ((k * k) + 1.0d);
            double chuiY = ((chuiX - ((double) sx)) * k) + ((double) sy);
            double judDis3 = Math.sqrt(((((double) jugx) - chuiX) * (((double) jugx) - chuiX)) + ((((double) jugy) - chuiY) * (((double) jugy) - chuiY)));
            MyLog.e(TAG, "getPointToLineDistence 斜率大于0:" + judDis3);
            return 0.0d <= judDis3 && judDis3 <= 10.0d;
        }
    }

    public static int[] getMaxAndMin(ArrayList<com.demostic.demostic_test.entity.Point> list) {
        int xmin = list.get(0).x;
        int xmax = xmin;
        int ymin = list.get(0).y;
        int ymax = ymin;
        for (int i = 1; i < list.size(); i++) {
            com.demostic.demostic_test.entity.Point point = list.get(i);
            if (point.x > xmax) {
                xmax = point.x;
            }
            if (point.x < xmin) {
                xmin = point.x;
            }
            if (point.y > ymax) {
                ymax = point.y;
            }
            if (point.y < ymin) {
                ymin = point.y;
            }
        }
        return new int[]{xmax, xmin, ymax, ymin};
    }

    public static int[] getLineInfoMaxAndMin(ArrayList<LineInfo> list) {
        int xmin = list.get(0).sx;
        int xmax = xmin;
        int ymin = list.get(0).sy;
        int ymax = ymin;
        int size = list.size();
        for (int i = 0; i < size; i++) {
            LineInfo info = list.get(i);
            if (info.ex > xmax) {
                xmax = info.ex;
            }
            if (info.ex < xmin) {
                xmin = info.ex;
            }
            if (info.ey > ymax) {
                ymax = info.ey;
            }
            if (info.ey < ymin) {
                ymin = info.ey;
            }
        }
        return new int[]{xmax, xmin, ymax, ymin};
    }

    public static int getMapID(byte b0, byte b1, byte b2, byte b3) {
        String st1 = Integer.toHexString(b0 & Draft_75.END_OF_FRAME);
        String st2 = Integer.toHexString(b1 & Draft_75.END_OF_FRAME);
        String st3 = Integer.toHexString(b2 & Draft_75.END_OF_FRAME);
        String st4 = Integer.toHexString(b3 & Draft_75.END_OF_FRAME);
        String str1 = getStr(st1);
        String str2 = getStr(st2);
        String str3 = getStr(st3);
        return Integer.parseInt((str1 + str2 + str3 + getStr(st4)).replace("f",""), 16);
    }

    public static String getStr(String string) {
        if (string.length() == 1) {
            return "0" + string;
        }
        return string;
    }

    public static com.demostic.demostic_test.entity.Point getLastPoint(byte[] roadbyte) {
        com.demostic.demostic_test.entity.Point lastP = new com.demostic.demostic_test.entity.Point();
        if (roadbyte.length >= 4) {
            int length = roadbyte.length;
            lastP.set(((bytesToInt(new byte[]{roadbyte[length - 4], roadbyte[length - 3]}, 0) * 224) / 100) + 750, 1500 - (((bytesToInt(new byte[]{roadbyte[length - 2], roadbyte[length - 1]}, 0) * 224) / 100) + 750));
        }
        return lastP;
    }

    public static int[] getMaxMin(int[] data) {
        int xn = data[0];
        int xm = xn;
        int yn = data[1];
        int ym = yn;
        for (int i = 2; i < data.length; i += 2) {
            int x = data[i];
            int y = data[i + 1];
            if (x > xm) {
                xm = x;
            }
            if (x < xn) {
                xn = x;
            }
            if (y > ym) {
                ym = y;
            }
            if (y < yn) {
                yn = y;
            }
        }
        return new int[]{xm, xn, ym, yn};
    }

    public static int judgeVirAndHostCharge(int sx, int sy, int ex, int ey, com.demostic.demostic_test.entity.Point mhostP, com.demostic.demostic_test.entity.Point mchargeP) {
        if (judgedVirAndCharge(sx, sy, ex, ey, mhostP) <= 10) {
            return 1;
        }
        if (judgedVirAndCharge(sx, sy, ex, ey, mchargeP) <= 10) {
            return 2;
        }
        return -1;
    }

    public static int judgeFbdAndHostCharge(int[] fbdary, com.demostic.demostic_test.entity.Point hostP, com.demostic.demostic_test.entity.Point chargeP, Path hostPH, Path chargePH) {
        jgPath = getPath(jgPath, fbdary);
        int[] mn = getMaxMin(fbdary);
        jgRegion.set(mn[1], mn[3], mn[0], mn[2]);
        jgRegion.setPath(jgPath, jgRegion);
        if (jgRegion.contains(hostP.x, hostP.y)) {
            return 1;
        }
        if (jgRegion.contains(chargeP.x, chargeP.y)) {
            return 2;
        }
        if (jgRegion.setPath(hostPH, jgRegion)) {
            return 3;
        }
        jgRegion.setEmpty();
        jgRegion.set(mn[1], mn[3], mn[0], mn[2]);
        jgRegion.setPath(jgPath, jgRegion);
        if (jgRegion.setPath(chargePH, jgRegion)) {
            return 4;
        }
        return -1;
    }

    public static Path getPath(Path path, int[] ary) {
        path.reset();
        path.moveTo((float) ary[0], (float) ary[1]);
        path.lineTo((float) ary[2], (float) ary[3]);
        path.lineTo((float) ary[4], (float) ary[5]);
        path.lineTo((float) ary[6], (float) ary[7]);
        path.close();
        return path;
    }

    public static ArrayList<VirTualInfo> decodeVirData(byte[] bt, boolean isSaveRect) {
        ArrayList<VirTualInfo> datalist = new ArrayList<>();
        byte virCount = bt[1];
        if (virCount != 0) {
            for (int i = 9; i < (virCount * 8) + 2; i += 8) {
                int startx = bytesToInt(new byte[]{bt[i - 7], bt[i - 6]}, 0);
                int[] virData = {startx + 750, 1500 - (bytesToInt(new byte[]{bt[i - 5], bt[i - 4]}, 0) + 750), bytesToInt(new byte[]{bt[i - 3], bt[i - 2]}, 0) + 750, 1500 - (bytesToInt(new byte[]{bt[i - 1], bt[i]}, 0) + 750)};
                VirTualInfo info = new VirTualInfo();
                info.setVirData(virData);
                info.setModifyed(false);
                if (isSaveRect) {
                    MapEditView901.saveRects(virData, info);
                } else {
                    info.setEnable(bt[0]);
                }
                datalist.add(info);
            }
        }
        return datalist;
    }

    public static ArrayList<ForbiddenInfo> decodeFbdData(byte[] bt, boolean isSaveRect) {
        ArrayList<ForbiddenInfo> datalist = new ArrayList<>();
        byte fbdCount = bt[83];
        if (fbdCount != 0) {
            for (int j = 100; j < (fbdCount * 17) + 84; j += 17) {
                int type = (bt[j - 16] & Draft_75.END_OF_FRAME) >> 4;
                int[] fbdData = {bytesToInt(new byte[]{bt[j - 15], bt[j - 14]}, 0) + 750, 1500 - (bytesToInt(new byte[]{bt[j - 13], bt[j - 12]}, 0) + 750), bytesToInt(new byte[]{bt[j - 11], bt[j - 10]}, 0) + 750, 1500 - (bytesToInt(new byte[]{bt[j - 9], bt[j - 8]}, 0) + 750), bytesToInt(new byte[]{bt[j - 7], bt[j - 6]}, 0) + 750, 1500 - (bytesToInt(new byte[]{bt[j - 5], bt[j - 4]}, 0) + 750), bytesToInt(new byte[]{bt[j - 3], bt[j - 2]}, 0) + 750, 1500 - (bytesToInt(new byte[]{bt[j - 1], bt[j]}, 0) + 750)};
                ForbiddenInfo info = new ForbiddenInfo();
                info.setFbdType(type);
                info.setModifyed(false);
                info.setFbdData(fbdData);
                if (isSaveRect) {
                    MapEditView901.saveForbidenPicRect(fbdData, info);
                } else {
                    info.setEnable(bt[82]);
                }
                datalist.add(info);
            }
        }
        return datalist;
    }

    public static ArrayList<ForbiddenInfo> decodeWhfData(byte[] bt, boolean isSaveRect) {
        ArrayList<ForbiddenInfo> datalist = new ArrayList<>();
        int ltx = bytesToInt(new byte[]{bt[0], bt[1]}, 0);
        int lty = bytesToInt(new byte[]{bt[2], bt[3]}, 0);
        int tpx = bytesToInt(new byte[]{bt[4], bt[5]}, 0);
        int tpy = bytesToInt(new byte[]{bt[6], bt[7]}, 0);
        int rtx = bytesToInt(new byte[]{bt[8], bt[9]}, 0);
        int rty = bytesToInt(new byte[]{bt[10], bt[11]}, 0);
        int btx = bytesToInt(new byte[]{bt[12], bt[13]}, 0);
        int bty = bytesToInt(new byte[]{bt[14], bt[15]}, 0);
        if (!(ltx == 0 && lty == 0 && rtx == 0 && rty == 0 && tpx == 0 && tpy == 0 && btx == 0 && bty == 0)) {
            int[] fbdData = {ltx + 750, 750 - lty, tpx + 750, 750 - tpy, rtx + 750, 750 - rty, btx + 750, 750 - bty};
            ForbiddenInfo info = new ForbiddenInfo();
            info.setFbdType(2);
            info.setFbdData(fbdData);
            if (isSaveRect) {
                MapEditView901.saveForbidenPicRect(fbdData, info);
            }
            datalist.add(info);
        }
        return datalist;
    }

    public static byte[] encodeVirFbdData(ArrayList<VirTualInfo> virInfo, ArrayList<ForbiddenInfo> fbdInfo) {
        byte[] dataBytes = new byte[254];
        if (virInfo != null && virInfo.size() > 0) {
            dataBytes[0] = 1;
            dataBytes[1] = (byte) virInfo.size();
            for (int i = 0; i < virInfo.size(); i++) {
                int[] virData = virInfo.get(i).getVirData();
                byte[] startxBytes = intToBytes(virData[0] - 750);
                byte[] startyBytes = intToBytes((1500 - virData[1]) - 750);
                byte[] endxBytes = intToBytes(virData[2] - 750);
                byte[] endyBytes = intToBytes((1500 - virData[3]) - 750);
                dataBytes[(i * 8) + 2] = startxBytes[0];
                dataBytes[(i * 8) + 3] = startxBytes[1];
                dataBytes[(i * 8) + 4] = startyBytes[0];
                dataBytes[(i * 8) + 5] = startyBytes[1];
                dataBytes[(i * 8) + 6] = endxBytes[0];
                dataBytes[(i * 8) + 7] = endxBytes[1];
                dataBytes[(i * 8) + 8] = endyBytes[0];
                dataBytes[(i * 8) + 9] = endyBytes[1];
            }
        }
        if (fbdInfo != null && fbdInfo.size() > 0) {
            dataBytes[82] = 1;
            dataBytes[83] = (byte) fbdInfo.size();
            for (int j = 0; j < fbdInfo.size(); j++) {
                ForbiddenInfo info = fbdInfo.get(j);
                int[] fbdData = info.getFbdData();
                byte tc = (byte) ((info.getFbdType() << 4) + 4);
                byte[] leftxByte = intToBytes(fbdData[0] - 750);
                byte[] leftyByte = intToBytes((1500 - fbdData[1]) - 750);
                byte[] topxByte = intToBytes(fbdData[2] - 750);
                byte[] topyByte = intToBytes((1500 - fbdData[3]) - 750);
                byte[] rightxByte = intToBytes(fbdData[4] - 750);
                byte[] rightyByte = intToBytes((1500 - fbdData[5]) - 750);
                byte[] bottomxByte = intToBytes(fbdData[6] - 750);
                byte[] bottomyByte = intToBytes((1500 - fbdData[7]) - 750);
                dataBytes[(j * 17) + 84] = tc;
                dataBytes[(j * 17) + 85] = leftxByte[0];
                dataBytes[(j * 17) + 86] = leftxByte[1];
                dataBytes[(j * 17) + 87] = leftyByte[0];
                dataBytes[(j * 17) + 88] = leftyByte[1];
                dataBytes[(j * 17) + 89] = topxByte[0];
                dataBytes[(j * 17) + 90] = topxByte[1];
                dataBytes[(j * 17) + 91] = topyByte[0];
                dataBytes[(j * 17) + 92] = topyByte[1];
                dataBytes[(j * 17) + 93] = rightxByte[0];
                dataBytes[(j * 17) + 94] = rightxByte[1];
                dataBytes[(j * 17) + 95] = rightyByte[0];
                dataBytes[(j * 17) + 96] = rightyByte[1];
                dataBytes[(j * 17) + 97] = bottomxByte[0];
                dataBytes[(j * 17) + 98] = bottomxByte[1];
                dataBytes[(j * 17) + 99] = bottomyByte[0];
                dataBytes[(j * 17) + 100] = bottomyByte[1];
            }
        }
        return dataBytes;
    }

    public static byte[] encodeWhgData(ArrayList<ForbiddenInfo> fbdInfo) {
        byte[] dataBytes = new byte[18];
        dataBytes[16] = 6;
        dataBytes[17] = 1;
        if (fbdInfo != null && fbdInfo.size() > 0) {
            int size = fbdInfo.size();
            for (int i = 0; i < size; i++) {
                int[] fbdData = fbdInfo.get(i).getFbdData();
                byte[] leftxByte = intToBytes(fbdData[0] - 750);
                byte[] leftyByte = intToBytes((1500 - fbdData[1]) - 750);
                byte[] topxByte = intToBytes(fbdData[2] - 750);
                byte[] topyByte = intToBytes((1500 - fbdData[3]) - 750);
                byte[] rightxByte = intToBytes(fbdData[4] - 750);
                byte[] rightyByte = intToBytes((1500 - fbdData[5]) - 750);
                byte[] bottomxByte = intToBytes(fbdData[6] - 750);
                byte[] bottomyByte = intToBytes((1500 - fbdData[7]) - 750);
                dataBytes[i] = leftxByte[0];
                dataBytes[i + 1] = leftxByte[1];
                dataBytes[i + 2] = leftyByte[0];
                dataBytes[i + 3] = leftyByte[1];
                dataBytes[i + 4] = topxByte[0];
                dataBytes[i + 5] = topxByte[1];
                dataBytes[i + 6] = topyByte[0];
                dataBytes[i + 7] = topyByte[1];
                dataBytes[i + 8] = rightxByte[0];
                dataBytes[i + 9] = rightxByte[1];
                dataBytes[i + 10] = rightyByte[0];
                dataBytes[i + 11] = rightyByte[1];
                dataBytes[i + 12] = bottomxByte[0];
                dataBytes[i + 13] = bottomxByte[1];
                dataBytes[i + 14] = bottomyByte[0];
                dataBytes[i + 15] = bottomyByte[1];
            }
        }
        return dataBytes;
    }
}
